//
//  TZEssenceItem.m
//  BSBDJ
//
//  Created by user on 16/5/25.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZEssenceItem.h"
#import "NSString+Extension.h"
@implementation TZEssenceItem

+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{
             @"small_image" : @"image0",
             @"large_image" : @"image1",
             @"middle_image" : @"image2"
             };
}

- (CGFloat)cellHeight{
    
    if (_cellHeight)  return _cellHeight;

    //0.头像的Y
    _cellHeight += 60;
    //1.从文字内容开始计算
    CGFloat textWidth = TZScreenW - 2 *TZMargin;
    CGFloat textH = [_text sizeWithFont:15 maxSize:CGSizeMake(textWidth, MAXFLOAT)].height;
    _cellHeight += 2 *TZMargin;
    _cellHeight += textH;
    //2.SHOWIMAGEVIEW
    if (_type == TZTopicTypePicture || _type == TZTopicTypeVoice || _type == TZTopicTypeVideo) {
        CGFloat picW = TZScreenW - 3 *TZMargin;
        //根据真实宽高计算 显示在屏幕上的宽高
        CGFloat picH = picW *self.height / self.width;
        CGFloat picY = 60 + textH + 2 *TZMargin;
        CGFloat picX = TZMargin;
        // 如果图片的真实高度大于1000 那么 设置H为300
        if (self.height >= TZPictureMaxHeight) {
            _is_BigImage = YES;
            picH = TZPictureNormolHeight;
        }
        // 计算frame
        _contentViewFrame = CGRectMake(picX, picY, picW, picH);
        _cellHeight += TZMargin;
        _cellHeight += picH;
        
    }
    
    // 最热评论区
    if (_top_cmt.count) {
        NSString *username = self.top_cmt.firstObject[@"user"][@"username"];
        NSString *content = self.top_cmt.firstObject[@"content"];
        if (content.length == 0) { // 没有文字内容，是个语音评论
            content = @"[语音评论]";
        }
        
        NSString *hotLabel = [NSString stringWithFormat:@"%@ : %@",username,content];
        CGFloat hotLabelHeight = [hotLabel sizeWithFont:14 maxSize:CGSizeMake( TZScreenW - 2 *TZMargin, MAXFLOAT)].height;
        // 最热评论四个字
        _cellHeight += 20;
        // 评论高度
        _cellHeight += hotLabelHeight;
        // 评论区 上下 间距
        _cellHeight +=2* TZMargin;
        // 功能区的高度
        _cellHeight += 35;
        return _cellHeight;
    }
    // 没有评论区的情况下  计算功能区的高度
    _cellHeight += 35;
    _cellHeight += 2 *TZMargin;
    
    return _cellHeight;
    
}


@end
